﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>
    <title>提交申请</title>
    <script src="../JS/mobiscroll.zepto.js"></script>
    <script src="../JS/mobiscroll.core.js"></script>
    <script src="../JS/mobiscroll.scroller.js"></script>
    <script src="../JS/mobiscroll.datetime.js"></script>
    <script src="../JS/mobiscroll.i18n.zh.js"></script>
    <script src="../JS/jquery.autoTextarea.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>

        var currYear = (new Date()).getFullYear();
        var opt = {
            date: { preset: 'date' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    model.ctData.BXDate = valueText;
                }
            }
        };
        function fun(str) {
            $("#appSDate").scroller($.extend(opt['date'], opt['defaultopi'])).scroller('setDate', str, true);
        }
    </script>
    <script>
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });


        var height = 0;
        var width = 0;
        var strId = "";
        var strIds = MobileCom.getQueryString("ids");

        var model = avalon.define({
            $id: "model",
            isforbid: "",
            code: "JFBX",
            lg: "",
            sh:"",
            rdm: Math.random(),
            ctData: { "BXZJE": 0, "BXContent": "", "ChaoSongRen": "", "Files": "", "ItemIds": strIds, "BXDate": "", "intProcessStanceid": "" },
            mxData: {},
            mxcount: 0,
            ptype: "0",
            wximg: "",
            delmx: function (el) {
                model.mxData.remove(el);
                model.ctData.BXZJE = model.ctData.BXZJE - el.BXJE;
                model.mxcount = model.mxcount - 1;
            },
            savedata: function () {
                if (model.ctData.BXDate == "") {
                    $.tips({
                        content: "请输入报销时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.BXContent == "") {
                    $.tips({
                        content: "请输入描述",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                model.ctData.ItemIds = "";
                model.ctData.BXZJE = 0;
                for (var i = 0; i < model.mxData.length; i++) {
                    if (model.ctData.ItemIds == "") {
                        model.ctData.ItemIds = model.mxData[i].ID;
                    }
                    else {
                        model.ctData.ItemIds = model.ctData.ItemIds + "," + model.mxData[i].ID;
                    }


                    model.ctData.BXZJE = model.ctData.BXZJE + model.mxData[i].BXJE;
                }
                if (model.ctData.ItemIds == "") {
                    var el = $.tips({
                        content: "消费记录为空，请返回选择！",
                        stayTime: 2000,
                        type: "warn"
                    })
                }
                else {

                    model.lg = $.loading({
                        content: '申请中...',
                    })

                    psmodel.savedata();

                    
                }
            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                $("#content").hide();
                $("#iframep").show();

                var cheight = height;
                var cwidth = width;

                $("#iframep").css("height", cheight);
                $("#iframep").css("width", cwidth);

            },
            bjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:' + (width - 76) + 'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入描述">' + model.ctData.BXContent + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.BXContent = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#hdjj").addClass("ui-txt-muted");
                            $("#hdjj").html("请输入描述");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
                $("#hdjjbjk").focus();
            }
        });

        function goback() {
            $("#content").show();
            $("#iframep").hide();
        }
        function goconfirm(json) {
            if (json != null) {
                $("#kh_fzry").removeClass("ui-txt-muted");
                $("#kh_fzry").html(json.vuser);
                model.ctData.ChaoSongRen = json.vusername;
            }
            else {
                $("#kh_fzry").addClass("ui-txt-muted");
                $("#kh_fzry").html('请选择抄送人');
                model.ctData.ChaoSongRen = '';
            }

            $("#content").show();
            $("#iframep").hide();
        }

        function Sava() {
            if (!model.ctData.intProcessStanceid) {
                model.lg.hide();
                $.tips({
                    content: "保存失败",
                    stayTime: 2000,
                    type: "warn"
                })
            }
            else {
                model.ctData.Files = "";
                $("#imglist .tpli").each(function () {
                    if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                        if (model.wximg) {
                            model.wximg += ",";
                        }
                        model.wximg += $(this).attr("itemid");

                    } else {
                        if (model.ctData.Files) {
                            model.ctData.Files = model.ctData.Files + ',' + $(this).attr("itemid");
                        }
                        else {
                            model.ctData.Files = $(this).attr("itemid");
                        }
                    }

                })
                $.post("/API/WXAPI.ashx?Action=ADDJFBX&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model), P2: model.wximg }, function (data) {
                    model.lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $(".ui-footer").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            //window.location = "UI_JFBX_BXMX.html?r=" + Math.random();
                            window.location.replace("UI_JFBX_BXMX.html?r=" + Math.random());
                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }

                })
            }
        }

        avalon.ready(function () {
            height = document.documentElement.clientHeight;
            width = document.documentElement.clientWidth;
            fun(new Date());
            model.ctData.RBDate = $("#BXDate").val();
            if (strIds != null) {
                model.lg = $.loading({
                    content: '加载中...',
                })
                $.getJSON('/API/WXAPI.ashx?Action=GETJFBXITEMBYIDS&r=' + Math.random(), { p1: strIds }, function (resultData) {

                    if (resultData.ErrorMsg == "") {
                        model.mxData = resultData.Result;
                        model.mxcount = model.mxData.length;
                        model.ctData.BXZJE = resultData.Result1;

                        setTimeout("load()", 500);
                    }
                })
                
            }
            $("#iframep").attr("src", "UI_PERSON.html?r=" + Math.random());
            $(".chackTextarea-area").autoTextarea({
                maxHeight: 220,
                minHeight: 80
            });
            MobileCom.uploadimg();
        })
    </script>
    <style>
        .ui-list > li {
            margin: 3px;
            padding-left: 15px;
        }
        .ui-form-item .wspan {
            width: 100%;
            display: -webkit-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

            .ui-form-item .wspan img {
                width: 50px;
                height: 50px;
                padding-right: 3px;
            }

        .sctp {
            color: #18b4ed;
            right: 4px;
            top: -5px;
            z-index: 9;
            width: 20px;
            height: 20px;
            background: #fff;
            border-radius: 13px;
            line-height: 20px;
            text-indent: -3px;
            position: absolute;
            font-size: 25px;
        }

        .imgxl {
            position: relative;
            float: left;
            padding-top: 0;
            height: 50px;
            width: 50px;
            padding-right: 10px;
            margin-left: 0px;
            margin-bottom: 5px;
        }

        .tpxs {
            height: 50px;
            width: 50px;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            background-repeat: no-repeat;
            -webkit-background-size: cover;
        }

        .ms-controller, [ms-controller] {
            display: none;
        }
    </style>
</head>
<body ms-controller="model">
    <div id="content">
        <header class="ui-header ui-header-stable ui-border-b">
            <i class="ui-icon-return" onclick="history.back(-1)"></i><h1>申请报销</h1>
        </header>
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg ui-btn-primary" ms-click="savedata()">
                提交申请
            </button>
            <button class="ui-btn-lg" onclick="history.back(-1)">
                取消
            </button>
        </div>

        <section class="ui-container">
            <div class="ui-form ui-border-t">
                <div class="ui-form-item ui-border-b">
                    <label>
                        报销时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="2015-07-10" id="appSDate" ms-duplex="ctData.BXDate" style="padding-left:0" />
                    </div>
                </div>
                <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;min-height:44px">
                    <label>
                        描述
                    </label>
                    <textarea placeholder="请输入描述" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.BXContent"></textarea>
                    <!--<input type="text" placeholder="请输入描述" ms-duplex="ctData.BXContent" />-->
                    <!--<div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="hdjj" ms-click="bjk()">请输入描述</div>-->
                </div>
                <!--<div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        抄送人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="kh_fzry" ms-click="selperson()">请选择抄送人</div>
                </div>-->
                <div ms-include-src="UI_PROCESS.html?r={{rdm}}">

                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        总金额
                    </label>
                    <span class="wspan">{{ctData.BXZJE}}</span>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        消费记录
                    </label>
                    <span class="wspan">共 {{mxcount}} 条</span>
                </div>
                <div class="ui-form ui-border-t">
                    <ul class="ui-list ui-list-pure">
                        <li class="ui-border ui-label-list" ms-repeat-el="mxData">
                            <p>
                                <span class="ui-txt-info">
                                    <label class="ui-label-s">
                                        {{el.LeiBie}}
                                    </label> {{el.BXJE}}元 {{el.BXDate|date("yyyy-MM-dd")}}
                                </span>
                                <span style="float:right"><button class="ui-btn ui-btn-danger" ms-click="delmx(el)" style="height:24px;line-height:24px">移除</button></span>
                            </p>
                            <p class="ui-txt-justify">事由：{{el.BXContent}}</p>
                        </li>
                    </ul>
                </div>
                <div class="ui-form-item ui-border-b" style="height:auto;min-height:44px">
                    <label>
                        上传图片
                    </label>

                    <div class="wspan" style="padding-top: 5px; height: auto;display:block">
                        <ul id="imglist">
                            <li class="imgxl scli"><img id="add_pit" src="../Images/icon-add.png" /></li>
                        </ul>
                        <div style="clear:both"></div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <iframe id="iframep" src="UI_PERSON.html" style="display: none; margin-bottom: -7px;" frameborder="0"></iframe>
</body>
</html>
